{{ define "main" }}

{{ $modulesList := .Site.Data.modules.channels }}
{{ $channelsInfo := .Site.Data.channels.info }}
{{ $sidebarRootMenu := slice }}
{{ $pages := (where $.Site.RegularPages ".Section" "modules").ByWeight }}
{{ $ctx := $ }}

{{ $_pathElements := index ( findRESubmatch  `^modules/([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/*$` .File.Dir 1 ) 0 }}
{{ $currentModuleName := index $_pathElements 1 }}
{{ $currentModuleChannel := index $_pathElements 2 }}

{{ range $module, $data := $modulesList }}
  {{ $moduleTitle := "" }}
  {{ $moduleChannel := "" }}
  {{ $moduleSummary := "" }}

  {{ range sort $channelsInfo "stability" "asc" }}
    {{ if gt ( $moduleTitle | len ) 0  }}{{ continue }}{{ end }}
    {{ $code := .code }}
    {{ with $.GetPage ( printf "modules/%s/%s/README.md" $module .code  ) }}
      {{ if .Params.menuTitle }}{{ $moduleTitle = .Params.menuTitle }}
      {{ else if .LinkTitle }}{{ $moduleTitle = .LinkTitle }}
      {{ end }}
      {{ if not $moduleChannel }}{{ $moduleChannel = $code }}{{ end }}
      {{ if not $moduleSummary }}{{ $moduleSummary = .Summary }}{{ end }}
    {{ end}}
  {{ end}}
  {{ if not $moduleTitle }}{{ $moduleTitle = $module }}{{ end }}
  {{ $sidebarRootMenu = $sidebarRootMenu | append (dict "module" $module "title" $moduleTitle "channel" $moduleChannel "summary" $moduleSummary ) }}
{{ end}}

{{ $sidebarRootMenu = sort $sidebarRootMenu "title" "asc" }}


<div class="docs docs--modules">
    <div class="docs__wrap-title">
        <h1 class="docs__title">{{ .Title }}</h1>
    </div>

    <div class="post-content">

     {{.Content}}

     {{ range $sidebarItem := slice }}
          <div style="border: 1px solid black; margin:10px; padding:10px; ">
               <div style="font-size:20px;">
                    <strong><a href="{{ printf "%s/%s/" $sidebarItem.module $sidebarItem.channel }}">{{ $sidebarItem.title }}</a></strong>{{/* if ne $sidebarItem.module $sidebarItem.title }} ({{ T "module" }} <code>{{ $sidebarItem.module }}</code>){{ end */}}
               </div>
               <p style="font-size:18px;">{{ $sidebarItem.summary }}</p>
          </div>
     {{ end }}
    </div>
</div>
{{ end }}
